Repository navigation
ao_two_e_ints: exact (ik|ik) Schwartz diagonals on the map path (finish #419) - #423
Merged
scemama merged 3 commits intoNov 19, 2026
Merged
Conversation
On the map path (do_ao_cholesky = False) the dispatcher ao_two_e_integral routes to ao_two_e_integral_schwartz_accel whenever the product of the primitive counts exceeds 1024, and that accelerator skips primitive quartets with the absolute threshold ao_integrals_threshold**2. The Schwartz screening factors ao_two_e_integral_schwartz(i,k) = sqrt((ik|ik)) were therefore computed from zeroed (or under-summed) diagonals, and the AO-level CS test then dropped integrals far above the threshold: on the (H2O)4 chain, cc-pVDZ, threshold 1e-15, 43/5050 factors came out exactly 0 and 34 482 integrals >= 1e-15 were dropped (largest 3.9e-9). The Cholesky path was unaffected (do_schwartz_accel is false when do_ao_cholesky), which is why the defect survived the sqrt((ik|ik)) fix of QuantumPackage#422. The full primitive sum (the dispatcher's final branch, moved verbatim) is now ao_two_e_integral_full, and the provider ao_two_e_integral_schwartz uses dsqrt(dabs(ao_two_e_integral_full(i,k,i,k))) - the same pattern the cGTO providers use since QuantumPackage#421 (dabs: a vanishing diagonal can be negative by rounding). Dispatcher behaviour is unchanged: its last branch is now a single call. The same defect existed on the long-range (erf) path, which routes to ao_two_e_integral_schwartz_accel_erf unconditionally above 1024 primitives; ao_two_e_integral_erf_full and ao_two_e_integral_erf_schwartz get the same treatment.
Per the proposal in issue QuantumPackage#419: the test ao_overlap_abs(j,l)*ao_overlap_abs(i,k) < ao_integrals_threshold is not a bound on (ik|jl) - it dropped integrals up to ~10x the threshold (5-8 bohr 1s example: S_ik*S_jl ~ 1e-15 while (ik|jl) = 1.1e-15). The rigorous CS bound sqrt((ik|ik)(jl|jl)) with exact diagonals (previous commit) subsumes it at zero cost: the factors are already provided. The BEGIN_DOC is rewritten: the integral tested is (ik|jl) (1st+3rd arguments = pair 1, 2nd+4th = pair 2), the real-GTO test is the rigorous Cauchy-Schwarz bound, and no integral above ao_integrals_threshold is screened. This also restores the doc fix that the merge 66de718 of QuantumPackage#422 dropped.
Closes the loop on issue QuantumPackage#419 with a deterministic regression test for the map path (do_ao_cholesky = False) now that the (ik|ik) Schwartz diagonals are exact. Fixture: a 12-atom (H2O)4 chain (tests/input/h2o4_chain.xyz, four water molecules at 2.9 A, cc-pVDZ), created by 00.create.bats like every other fixture. The chain geometry was chosen so that many cross-molecule (ik|ik) diagonals are small: it reproduces the issue's symptom on a system that SCFs in a few seconds. The test (B-B_screening_map in 10.hf.bats) runs the SCF with do_ao_cholesky = False and ao_integrals_threshold = 1.0e-15 and checks two things: - the map stores exactly 3916331 AO integrals. The count is the gate: with the exact diagonals it is deterministic, while the pre-fix accelerated path zeroed 881/5050 of the (ik|ik) diagonals on this chain (43/5050 on the issue's geometry) and the CS screening then dropped integrals far above the threshold; - the energy is -304.12427863337 (tolerance 1e-8), agreeing with the default Cholesky path (-304.124278633356) to 1.4e-11. io_ao_two_e_integrals is set to None: the "Write" mode of the 00.create fixture flips to "Read" after the first map dump, and the read path prints no "Number of AO integrals" line; None keeps the map computed on the fly on every run, which is the mode the constants were recorded in. Docs: docs/source/modules/ao_two_e_ints.rst is updated for the rewritten and new docstrings (ao_two_e_integral_full, ao_two_e_integral_erf_full, the ao_two_e_integral_schwartz providers, ao_two_e_integral_zero) and gains the previously undocumented ao_two_e_integral_schwartz_cgtos provider. Only the page whose sources changed is touched; the unrelated drift a local full regeneration would have introduced (module-prefixed File: lines, needs lists of modules not built here) is kept out of the diff.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #419 was reopened on 2026-11-19 because the merge of PR #422 (fd7faae,
merged as 66de718) left one defect: on the map path (do_ao_cholesky = False)
the dispatcher ao_two_e_integral routes to ao_two_e_integral_schwartz_accel
whenever nprim(i)*nprim(j)*nprim(k)*nprim(l) > 1024, and that accelerator
skips primitive quartets with the absolute threshold
ao_integrals_threshold**2. The Schwartz screening factors
ao_two_e_integral_schwartz(i,k) = sqrt((ik|ik)) were therefore computed from
zeroed (or under-summed) diagonals, and the AO-level CS test then dropped
integrals far above the threshold. Measured on the reopened issue, threshold
1e-15, do_ao_cholesky = False:
34 482 integrals >= 1e-15 dropped, largest 3.9e-9
The Cholesky path was unaffected (do_schwartz_accel is false when
do_ao_cholesky). The same defect existed on the long-range (erf) path, which
routes to ao_two_e_integral_schwartz_accel_erf unconditionally above 1024
primitives.
Commits
verbatim move of the dispatcher's final branch (full primitive sum),
so the dispatcher's last branch is a single call (no behaviour change
on the Cholesky path: there the diagonals were already the full sum).
ao_two_e_integral_erf_schwartz now use dsqrt(dabs((i,k,i,k))) —
the same pattern the cGTO providers use since cGTOs: rigorous Cauchy-Schwarz screening of the AO two-electron integrals #421.
Per the issue Proposal: the test ao_overlap_abs(j,l)ao_overlap_abs(i,k)
< thr is not a bound on (ik|jl) (it dropped integrals up to ~10x the
threshold, e.g. S_ikS_jl ~ 1e-15 with (ik|jl) = 1.1e-15); the rigorous
CS bound with exact diagonals subsumes it at zero cost. The BEGIN_DOC is
rewritten — this also restores the doc fix (integral is (ik|jl), bound
sqrt((ik|ik)(jl|jl))) that merge 66de718 dropped from ao_two_e_ints: same-side Schwartz bound sqrt((ik|ik)) (fix #419) #422.
O-O spacing 2.9 A) + 00.create.bats entry.
threshold 1e-15; the map stores exactly the integrals >= threshold
that pass the rigorous CS bound, so the printed count is
deterministic and is the regression gate (the SCF energy moves by
~1e-10 only).
sources changed; the new functions, the rewritten docstrings and the
previously undocumented ao_two_e_integral_schwartz_cgtos provider).
Evidence (this branch, macmini arm64, cc-pVDZ, (H2O)4 chain, threshold 1e-15)
reporter's chain; the same probe re-measured on this branch's test chain
gives 881/5050 pre-fix and 0 post-fix (the diagonals are now the full
primitive sum by construction).
(34 482 on the issue's chain).
path (Eref) to 1.4e-11.
chain: every quartet it killed also fails the magnitude test.
unchanged Cholesky-path energies (B-B -48.9950585434279,
B-B_screening, HCN -92.88717500035233, ...); with the new test the suite
is 34/34.